import { shareOptions } from "../../utils/access";
import request from "../../utils/request";
const api = require("../../config/api");
const wxParse = require("../../utils/wxParse/wxParse.js");
import { getStorage } from "../../utils/utils"
// pages/idleAddOrder/idleAddOrder.js
Page({
	/**
	 * 页面的初始数据
	 */
	data: {
		id: "",
		phone: "",
		goodsInfo: {},
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function (options) {
		let phone = getStorage("phone");
		this.setData({
			id: options.id,
			phone: phone,
		});
		wx.setNavigationBarColor({
			frontColor: "#000000",
			backgroundColor: "#f5f5f5",
		});

		this.getGoodsDetail(options.id);
	},
	async goPlay() {
		wx.showLoading({
			title: "加载中…",
			icon: "loading",
			duration: 10000,
			mask: true,
		});

		let id = this.data.id;
		const res = await request.post(api.idleOrderBuy, { goodsId: id });

		if (res?.httpStatus == 200) {
			wx.navigateTo({
				url: `/pages/idlePay/idlePay?orderNo=` + res.data.orderNo,
			});
			wx.hideLoading();
		} else {
			wx.hideLoading();
			wx.showToast({
				title: res.msg,
				icon: "error",
				duration: 2000,
			});
		}
	},
	async getGoodsDetail(id) {
		const res = await request.get(api.goodsDetail, { id }, { loading: false });
		this.setData({
			goodsInfo: res.data,
		});
	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () {},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function () {},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function () {},

	// 用户点击右上角分享
	onShareAppMessage(e) {
		return shareOptions('default', e)
	},
});
